from machine import Timer
import time

def my_callback(t):
    print("Timer triggered!")

# 实例化一个软定时器
tim = Timer(-1)

# 初始化定时器为单次模式，周期100ms
tim.init(period=100, mode=Timer.ONE_SHOT, callback=lambda t:print("timer_soft one shot!"))
time.sleep(0.25)

# 初始化定时器为周期模式，频率为1Hz
tim.init(freq=1, mode=Timer.PERIODIC, callback=my_callback)
time.sleep(1)
#time.sleep_ms(1000)
#time.sleep_us(10000)

## 释放定时器资源
#tim.deinit()

# 保持主循环运行
while True:
    print("hello micropython.")
    time.sleep(1)
